package com.albaba.designpattern.command.text_001;

import org.springframework.util.StringUtils;

import java.util.ArrayList;

/**
 * @Description: Waiter 服务员 -> Invoker
 * @Author zx
 * @Date 2025/2/27 17:10
 * @Version 1.0
 */
public class Waiter {

    // 可以持有多个命令对象
    private ArrayList<Command> commands;

    public Waiter() {
        commands = new ArrayList<Command>();
    }

    public Waiter(ArrayList<Command> commands) {
        this.commands = commands;
    }

    public void setCommands(Command commands) {
        this.commands.add(commands);
    }

    // 发出指令
    public void orderUp() {
        System.out.println("服务员：来点菜");
        for (Command command : commands) {
            if (!StringUtils.isEmpty(command)){
                command.execute();
            }
        }
    }
}
